<template>
  <div class="wrap">
    <homeHeader></homeHeader>
    <swiper :list="swiper"></swiper>
    <indexItems :list="icons"></indexItems>
    <recomend :recommend="recommend"></recomend>
    <weekend :weekend="weekend"></weekend>
  </div>
</template>

<script>
import homeHeader from './components/header'
import swiper from './components/swiper'
import indexItems from './components/items'
import recomend from './components/recomend'
import weekend from './components/weekend'
import axios from 'axios'
import { mapState } from 'vuex'
export default {
  name: 'Home',
  components: {
    homeHeader,
    swiper,
    indexItems,
    recomend,
    weekend
  },
  data () {
    return {
      lastCity: '',
      swiper: [],
      icons: [],
      recommend: [],
      weekend: []
    }
  },
  computed: {
    ...mapState(['city'])
  },
  methods: {
    getHomeInfo () {
      this.lastCity = this.city
      axios.get('/api/index.json?city' + this.city)
        .then(this.getHomeInfoSucc)
    },
    getHomeInfoSucc (res) {
      res = res.data
      if (res.ret && res.data) {
        const data = res.data
        this.swiper = data.swiperList
        this.icons = data.iconList
        this.recommend = data.recommendList
        this.weekend = data.weekendList
      }
    }
  },
  mounted () {
    this.getHomeInfo()
  },
  activated () {
    if (this.lastCity !== this.city) {
      this.getHomeInfo()
    }
  }
}
</script>

<style lang="stylus" scoped>
  .wrap
    font-size: 28px/*px*/
</style>
